package com.netsdk.demo.customize.gateway;

import static com.netsdk.lib.NetSDKLib.NET_ALARM_ARC_OFFLINE;
import static com.netsdk.lib.NetSDKLib.NET_ALARM_AREAALARM;
import static com.netsdk.lib.NetSDKLib.NET_ALARM_ARMING_FAILURE;
import static com.netsdk.lib.NetSDKLib.NET_ALARM_ATS_FAULT;
import static com.netsdk.lib.NetSDKLib.NET_ALARM_BATTERYLOWPOWER;
import static com.netsdk.lib.NetSDKLib.NET_ALARM_CHASSISINTRUDED;
import static com.netsdk.lib.NetSDKLib.NET_ALARM_MANUAL_TEST;
import static com.netsdk.lib.NetSDKLib.NET_ALARM_OVER_TEMPERATURE;
import static com.netsdk.lib.NetSDKLib.NET_ALARM_POWERFAULT;
import static com.netsdk.lib.NetSDKLib.NET_ALARM_RCEMERGENCY_CALL;
import static com.netsdk.lib.NetSDKLib.NET_ALARM_RF_JAMMING;
import static com.netsdk.lib.NetSDKLib.NET_ALARM_SENSOR_ABNORMAL;
import static com.netsdk.lib.NetSDKLib.NET_ALARM_USER_MODIFIED;
import static com.netsdk.lib.NetSDKLib.NET_ALARM_WIFI_FAILURE;
import static com.netsdk.lib.Utils.getOsPrefix;

import java.io.File;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;

import com.netsdk.demo.util.CaseMenu;
import com.netsdk.lib.NetSDKLib;
import com.netsdk.lib.ToolKits;
import com.netsdk.lib.NetSDKLib.ALARM_BATTERYLOWPOWER_INFO;
import com.netsdk.lib.NetSDKLib.ALARM_CHASSISINTRUDED_INFO;
import com.netsdk.lib.NetSDKLib.ALARM_POWERFAULT_INFO;
import com.netsdk.lib.NetSDKLib.ALARM_RCEMERGENCY_CALL_INFO;
import com.netsdk.lib.NetSDKLib.CFG_DEV_DISPOSITION_INFO;
import com.netsdk.lib.NetSDKLib.CFG_DVRIP_INFO;
import com.netsdk.lib.NetSDKLib.CFG_NETWORK_INFO;
import com.netsdk.lib.NetSDKLib.EM_UPGRADE_TYPE;
import com.netsdk.lib.NetSDKLib.LLong;
import com.netsdk.lib.callback.impl.DefaultDisconnectCallback;
import com.netsdk.lib.callback.impl.DefaultHaveReconnectCallBack;
import com.netsdk.lib.enumeration.EM_ALARM_ONECLICKARMING_FUNCTION;
import com.netsdk.lib.enumeration.EM_ALARM_ONECLICKARMING_TRIGGEROPTION;
import com.netsdk.lib.enumeration.EM_ALARM_USERAUTHORITY;
import com.netsdk.lib.enumeration.EM_ALARM_USER_GROUP;
import com.netsdk.lib.enumeration.EM_AREAARM_TRIGGERMODE;
import com.netsdk.lib.enumeration.EM_ARM_TYPE;
import com.netsdk.lib.enumeration.EM_CFG_APN;
import com.netsdk.lib.enumeration.EM_CODEID_SENSE_METHOD_TYPE;
import com.netsdk.lib.enumeration.EM_GETUSERINFOBYCONDITION_USER_STATUS;
import com.netsdk.lib.enumeration.EM_GETUSERINFOBYCONDITION_USER_TYPE;
import com.netsdk.lib.enumeration.EM_NEW_CONFIG;
import com.netsdk.lib.enumeration.EM_OPERATE_USERINFO_TYPE;
import com.netsdk.lib.enumeration.EM_SDK_LOG_QUERY_TYPE;
import com.netsdk.lib.enumeration.EM_WIRELESS_DEVICE_MODE;
import com.netsdk.lib.enumeration.ENUMERROR;
import com.netsdk.lib.enumeration.NET_CODEID_ERROR_TYPE;
import com.netsdk.lib.enumeration.NET_EM_CFG_OPERATE_TYPE;
import com.netsdk.lib.enumeration.NET_EM_SCENE_MODE;
import com.netsdk.lib.enumeration.NET_EM_SET_ALARMREGION_INFO;
import com.netsdk.lib.enumeration.NET_WIRELESS_DEVICE_TYPE;
import com.netsdk.lib.structure.ALARM_AREAALARM_INFO;
import com.netsdk.lib.structure.ALARM_AREAARM_MODECHANGE_INFO;
import com.netsdk.lib.structure.ALARM_KEYPAD_LOCK_INFO;
import com.netsdk.lib.structure.ALARM_WIRELESSDEV_LOWPOWER_INFO;
import com.netsdk.lib.structure.ALARM_WIRELESSDEV_POWERLESS_INFO;
import com.netsdk.lib.structure.CFG_ALARM_SUBSYSTEM_INFO;
import com.netsdk.lib.structure.CFG_CHASSISINTRUSION_INFO;
import com.netsdk.lib.structure.CFG_NETAPP_WLAN;
import com.netsdk.lib.structure.CFG_SCENE_MODE_INFO;
import com.netsdk.lib.structure.CFG_WIRELESS_INFO;
import com.netsdk.lib.structure.NET_ALARM_ARC_OFFLINE_INFO;
import com.netsdk.lib.structure.NET_ALARM_ARMING_FAILURE_INFO;
import com.netsdk.lib.structure.NET_ALARM_ATS_FAULT_INFO;
import com.netsdk.lib.structure.NET_ALARM_DEVICE_MODIFIED_INFO;
import com.netsdk.lib.structure.NET_ALARM_MANUAL_TEST_INFO;
import com.netsdk.lib.structure.NET_ALARM_OVER_TEMPERATURE_INFO;
import com.netsdk.lib.structure.NET_ALARM_RF_JAMMING_INFO;
import com.netsdk.lib.structure.NET_ALARM_USER_EXTERN;
import com.netsdk.lib.structure.NET_ALARM_USER_MODIFIED_INFO;
import com.netsdk.lib.structure.NET_ALARM_WIFI_FAILURE_INFO;
import com.netsdk.lib.structure.NET_CFG_AREA_ARM_MODE_INFO;
import com.netsdk.lib.structure.NET_CFG_DISABLE_BEEP_LINKAGE_INFO;
import com.netsdk.lib.structure.NET_CTRL_LOWRATEWPAN_ADD;
import com.netsdk.lib.structure.NET_CTRL_LOWRATEWPAN_REMOVE;
import com.netsdk.lib.structure.NET_CTRL_LOWRATEWPAN_REMOVEALL;
import com.netsdk.lib.structure.NET_DEVSTATUS_NET_INFO;
import com.netsdk.lib.structure.NET_DEVSTATUS_POWER_INFO;
import com.netsdk.lib.structure.NET_DEVSTATUS_SIM_INFO;
import com.netsdk.lib.structure.NET_EVENT_AREAR_INFO;
import com.netsdk.lib.structure.NET_GET_ACCESSORY_INFO;
import com.netsdk.lib.structure.NET_IN_ADD_ALARM_USER;
import com.netsdk.lib.structure.NET_IN_ATTACH_LOWRATEWPAN;
import com.netsdk.lib.structure.NET_IN_CTRL_LOWRATEWPAN_ACCESSORY_PARAM;
import com.netsdk.lib.structure.NET_IN_DELETE_ALARM_USER;
import com.netsdk.lib.structure.NET_IN_GET_DEVICESERIALNO_INFO;
import com.netsdk.lib.structure.NET_IN_GET_DEVICETYPE_INFO;
import com.netsdk.lib.structure.NET_IN_MANUAL_TEST;
import com.netsdk.lib.structure.NET_IN_MODIFY_ALARM_USER;
import com.netsdk.lib.structure.NET_IN_MODIFY_ALARM_USER_PASSWORD;
import com.netsdk.lib.structure.NET_IN_SET_ALARMMODE;
import com.netsdk.lib.structure.NET_IN_TRANSMIT_CMD;
import com.netsdk.lib.structure.NET_IN_UNIFIEDINFOCOLLECT_GET_DEVSTATUS;
import com.netsdk.lib.structure.NET_IN_WLAN_ACCESSPOINT;
import com.netsdk.lib.structure.NET_NETAPP_COMMUNICATION_LIST_CFG;
import com.netsdk.lib.structure.NET_OUT_ADD_ALARM_USER;
import com.netsdk.lib.structure.NET_OUT_ATTACH_LOWRATEWPAN;
import com.netsdk.lib.structure.NET_OUT_DELETE_ALARM_USER;
import com.netsdk.lib.structure.NET_OUT_GET_DEVICESERIALNO_INFO;
import com.netsdk.lib.structure.NET_OUT_GET_DEVICETYPE_INFO;
import com.netsdk.lib.structure.NET_OUT_MANUAL_TEST;
import com.netsdk.lib.structure.NET_OUT_MODIFY_ALARM_USER;
import com.netsdk.lib.structure.NET_OUT_MODIFY_ALARM_USER_PASSWORD;
import com.netsdk.lib.structure.NET_OUT_SET_ALARMMODE;
import com.netsdk.lib.structure.NET_OUT_TRANSMIT_CMD;
import com.netsdk.lib.structure.NET_OUT_UNIFIEDINFOCOLLECT_GET_DEVSTATUS;
import com.netsdk.lib.structure.NET_OUT_WLAN_ACCESSPOINT;
import com.netsdk.lib.structure.NET_TIME;
import com.netsdk.lib.structure.NET_TIME_EX;
import com.netsdk.lib.structure.NET_WLAN_ACCESSPOINT_INFO;
import com.netsdk.lib.structure.NET_WPAN_ACCESSORY_INFO;
import com.netsdk.lib.structure.QUERY_DEVICE_LOG_PARAM;
import com.netsdk.lib.structure.SDK_DEVICE_LOG_ITEM_EX;
import com.sun.jna.Memory;
import com.sun.jna.Native;
import com.sun.jna.NativeLong;
import com.sun.jna.Pointer;
import com.sun.jna.ptr.IntByReference;

public class GatewayDemo {
	// SDk对象初始化
	public static final NetSDKLib netsdk = NetSDKLib.NETSDK_INSTANCE;
	public static final NetSDKLib configsdk = NetSDKLib.CONFIG_INSTANCE;

	// 判断是否初始化
	private static boolean bInit = false;
	// 判断log是否打开
	private static boolean bLogOpen = false;
	// 设备信息
	private NetSDKLib.NET_DEVICEINFO_Ex deviceInfo = new NetSDKLib.NET_DEVICEINFO_Ex();
	// 登录句柄
	private NetSDKLib.LLong m_hLoginHandle = new NetSDKLib.LLong(0);

	// 回调函数需要是静态的，防止被系统回收
	// 断线回调
	private static NetSDKLib.fDisConnect disConnectCB = DefaultDisconnectCallback.getINSTANCE();
	// 重连回调
	private static NetSDKLib.fHaveReConnect haveReConnectCB = DefaultHaveReconnectCallBack.getINSTANCE();

	// 编码格式
	public static String encode;

	static {
		String osPrefix = getOsPrefix();
		if (osPrefix.toLowerCase().startsWith("win32-amd64")) {
			encode = "GBK";
		} else if (osPrefix.toLowerCase().startsWith("linux-amd64")) {
			encode = "UTF-8";
		}
	}

	/**
	 * 获取当前时间
	 */
	public static String GetDate() {
		SimpleDateFormat simpleDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		return simpleDate.format(new java.util.Date()).replaceAll("[^0-9]", "-");
	}

	/**
	 * 初始化SDK库
	 */
	public static boolean Init() {
		bInit = netsdk.CLIENT_Init(disConnectCB, null);// 进程启动时，初始化一次
		if (!bInit) {
			System.out.println("Initialize SDK failed");
			return false;
		}
		// 配置日志
		GatewayDemo.enableLog();

		// 设置断线重连回调接口, 此操作为可选操作，但建议用户进行设置
		netsdk.CLIENT_SetAutoReconnect(haveReConnectCB, null);

		// 设置登录超时时间和尝试次数，可选
		// 登录请求响应超时时间设置为3S
		int waitTime = 3000;
		// 登录时尝试建立链接 1 次
		int tryTimes = 1;
		netsdk.CLIENT_SetConnectTime(waitTime, tryTimes);
		// 设置更多网络参数， NET_PARAM 的nWaittime ， nConnectTryNum 成员与 CLIENT_SetConnectTime
		// 接口设置的登录设备超时时间和尝试次数意义相同,可选
		NetSDKLib.NET_PARAM netParam = new NetSDKLib.NET_PARAM();
		// 登录时尝试建立链接的超时时间
		netParam.nConnectTime = 10000;
		// 设置子连接的超时时间
		netParam.nGetConnInfoTime = 3000;
		netsdk.CLIENT_SetNetworkParam(netParam);
		return true;
	}

	/**
	 * 打开 sdk log
	 */
	private static void enableLog() {
		NetSDKLib.LOG_SET_PRINT_INFO setLog = new NetSDKLib.LOG_SET_PRINT_INFO();
		File path = new File("sdklog/");
		if (!path.exists())
			path.mkdir();

		// 这里的log保存地址依据实际情况自己调整
		String logPath = path.getAbsoluteFile().getParent() + "\\sdklog\\" + "sdklog" + GetDate() + ".log";
		setLog.nPrintStrategy = 0;
		setLog.bSetFilePath = 1;
		System.arraycopy(logPath.getBytes(), 0, setLog.szLogFilePath, 0, logPath.getBytes().length);
		System.out.println(logPath);
		setLog.bSetPrintStrategy = 1;
		bLogOpen = netsdk.CLIENT_LogOpen(setLog);
		if (!bLogOpen)
			System.err.println("Failed to open NetSDK log");
	}

	/**
	 * 高安全登录
	 */
	public void loginWithHighLevel() {
		// 输入结构体参数
		NetSDKLib.NET_IN_LOGIN_WITH_HIGHLEVEL_SECURITY pstlnParam = new NetSDKLib.NET_IN_LOGIN_WITH_HIGHLEVEL_SECURITY() {
			{
				szIP = m_strIpAddr.getBytes();
				nPort = m_nPort;
				szUserName = m_strUser.getBytes();
				szPassword = m_strPassword.getBytes();
			}
		};
		// 输出结构体参数
		NetSDKLib.NET_OUT_LOGIN_WITH_HIGHLEVEL_SECURITY pstOutParam = new NetSDKLib.NET_OUT_LOGIN_WITH_HIGHLEVEL_SECURITY();

		// 写入sdk
		m_hLoginHandle = netsdk.CLIENT_LoginWithHighLevelSecurity(pstlnParam, pstOutParam);
		if (m_hLoginHandle.longValue() == 0) {
			System.err.printf("Login Device[%s] Port[%d]Failed. %s\n", m_strIpAddr, m_nPort,
					netsdk.CLIENT_GetLastError());
		} else {
			deviceInfo = pstOutParam.stuDeviceInfo; // 获取设备信息
			System.out.println("Login Success");
			System.out.println("Device Address：" + m_strIpAddr);
			System.out.println("设备包含：" + deviceInfo.byChanNum + "个通道");
		}
	}

	/**
	 * 退出
	 */
	public void logOut() {
		if (m_hLoginHandle.longValue() != 0) {
			netsdk.CLIENT_Logout(m_hLoginHandle);
			System.out.println("LogOut Success");
		}
	}

	/**
	 * 清理sdk环境并退出
	 */
	public static void cleanAndExit() {
		if (bLogOpen) {
			netsdk.CLIENT_LogClose(); // 关闭sdk日志打印
		}
		netsdk.CLIENT_Cleanup(); // 进程关闭时，调用一次
		System.exit(0);
	}

	/**
	 * 订阅报警信息
	 * 
	 */
	public void startListen() {
		// 设置报警回调函数设置一次即可
		netsdk.CLIENT_SetDVRMessCallBack(fAlarmAccessDataCB.getInstance(), null);

		// 订阅报警
		boolean bRet = netsdk.CLIENT_StartListenEx(m_hLoginHandle);
		if (!bRet) {
			System.err.println("订阅报警失败! LastError = 0x%x\n" + netsdk.CLIENT_GetLastError());
		} else {
			System.out.println("订阅报警成功.");
		}
	}

	/**
	 * 报警事件回调
	 */
	private static class fAlarmAccessDataCB implements NetSDKLib.fMessCallBack {
		private static fAlarmAccessDataCB instance = new fAlarmAccessDataCB();

		private fAlarmAccessDataCB() {
		}

		public static fAlarmAccessDataCB getInstance() {
			return instance;
		}

		@Override
		public boolean invoke(int lCommand, LLong lLoginID, Pointer pStuEvent, int dwBufLen, String strDeviceIP,
				NativeLong nDevicePort, Pointer dwUser) {
			switch (lCommand) {
			case NetSDKLib.NET_ALARM_AREAARM_MODECHANGE: { // 区域防区模式改变(对应结构体ALARM_AREAARM_MODECHANGE_INFO)
				System.out.println("区域防区模式改变事件--------------------");
				ALARM_AREAARM_MODECHANGE_INFO msg = new ALARM_AREAARM_MODECHANGE_INFO();
				ToolKits.GetPointerData(pStuEvent, msg);
				// 区域编号
				int nAreaIndex = msg.nAreaIndex;
				int nEventID = msg.nEventID;
				NET_TIME_EX utc = msg.UTC;
				int emTriggerMode = msg.emTriggerMode;
				int emUser = msg.emUser;
				int nID = msg.nID;
				System.out.println(" nAreaIndex:" + nAreaIndex);
				System.out.println(" nEventID:" + nEventID);
				System.out.println(" utc:" + utc);
				System.out.println(" emTriggerMode:" + emTriggerMode);
				System.out.println(" emUser:" + emUser);
				System.out.println(" nID:" + nID);
				break;
			}
			case NetSDKLib.NET_ALARM_ALARM_EX2: { // 本地报警事件(对应结构体 ALARM_ALARM_INFO_EX2)
				System.out.println(" 本地报警事件--------------------");
				NetSDKLib.ALARM_ALARM_INFO_EX2 msg = new NetSDKLib.ALARM_ALARM_INFO_EX2();
				ToolKits.GetPointerData(pStuEvent, msg);
				System.out.println("Channel is " + msg.nChannelID);
				System.out.println("Action is " + msg.nAction);
				System.out.println("Happend time is " + msg.stuTime.toStringTime());
				System.out.println("Sense type is " + msg.emSenseType + "\r\n");
				System.out.println("Defence area type is " + msg.emDefenceAreaType);
				break;
			}
			case NetSDKLib.NET_ALARM_WIRELESSDEV_LOWPOWER: { // 获取无线设备低电量上报事件(对应结构体ALARM_WIRELESSDEV_LOWPOWER_INFO)
				System.out.println(" 获取无线设备低电量上报事件--------------------");
				ALARM_WIRELESSDEV_LOWPOWER_INFO msg = new ALARM_WIRELESSDEV_LOWPOWER_INFO();
				ToolKits.GetPointerData(pStuEvent, msg);
				int emResult = msg.emResult;
				System.out.println(" emResult:" + emResult);
				NET_TIME stuTime = msg.stuTime;
				System.out.println(" stuTime:" + stuTime.toStringTime());
				int emType = msg.emType;
				System.out.println(" emType:" + emType);
				break;
			}
			case NetSDKLib.NET_ALARM_MODULE_LOST: { // 扩展模块掉线事件(对应结构体 ALARM_MODULE_LOST_INFO)
				System.out.println(" 扩展模块掉线事件--------------------");
				NetSDKLib.ALARM_MODULE_LOST_INFO msg = new NetSDKLib.ALARM_MODULE_LOST_INFO();
				ToolKits.GetPointerData(pStuEvent, msg);
				// 事件上报时间
				NetSDKLib.NET_TIME stuTime = msg.stuTime;
				System.out.println(" stuTime:" + stuTime.toStringTime());
				// 扩展模块接的总线的序号(从0开始)
				int nSequence = msg.nSequence;
				System.out.println(" nSequence:" + nSequence);
				// 总线类型, 参考枚举 NET_BUS_TYPE
				int emBusType = msg.emBusType;
				System.out.println(" emBusType:" + emBusType);
				// 掉线的扩展模块数目
				int nAddr = msg.nAddr;
				System.out.println(" nAddr:" + nAddr);
				// 掉线的扩展模块的序号(从0开始)
				int[] anAddr = msg.anAddr;
				for (int i = 0; i < nAddr; i++) {
					System.out.println(anAddr[i]);
				}
				// 设备类型 "SmartLock",是级联设备,当设备类型"AlarmDefence"接口序号为报警序号
				System.out.println(" szDevType:" + new String(msg.szDevType));
				// 在线情况 默认0。 0-不在线; 1-在线
				System.out.println(" bOnline:" + msg.bOnline);
				break;
			}
			case NET_ALARM_SENSOR_ABNORMAL: {// 探测器异常报警(对应结构体 ALARM_SENSOR_ABNORMAL_INFO)
				System.out.println(" 探测器异常报警--------------------");
				NetSDKLib.ALARM_SENSOR_ABNORMAL_INFO msg = new NetSDKLib.ALARM_SENSOR_ABNORMAL_INFO();
				ToolKits.GetPointerData(pStuEvent, msg);
				int nAction = msg.nAction;
				System.out.println(" nAction:" + nAction);
				int nChannelID = msg.nChannelID;
				System.out.println(" nChannelID:" + nChannelID);
				NetSDKLib.NET_TIME_EX stuTime = msg.stuTime;
				System.out.println(" stuTime:" + stuTime.toStringTime());
				System.out.println(" emStatus:" + msg.emStatus);
				break;
			}
			case NET_ALARM_RCEMERGENCY_CALL: {// 紧急呼叫报警事件(对应结构体 ALARM_RCEMERGENCY_CALL_INFO)
				System.out.println(" 紧急呼叫报警事件--------------------");
				ALARM_RCEMERGENCY_CALL_INFO msg = new ALARM_RCEMERGENCY_CALL_INFO();
				ToolKits.GetPointerData(pStuEvent, msg);
				System.out.println(" nAction:" + msg.nAction);
				System.out.println(" emType:" + msg.emType);
				System.out.println(" Happend:" + msg.stuTime.toStringTime());
				System.out.println(" emMode:" + msg.emMode);
				System.out.println(" dwID:" + msg.dwID);
				break;
			}
			case NET_ALARM_BATTERYLOWPOWER: { // 电池电量低报警(对应结构体 ALARM_BATTERYLOWPOWER_INFO)
				System.out.println(" 电池电量低报警--------------------");
				ALARM_BATTERYLOWPOWER_INFO msg = new ALARM_BATTERYLOWPOWER_INFO();
				ToolKits.GetPointerData(pStuEvent, msg);
				// 0:开始1:停止
				int nAction = msg.nAction;
				System.out.println(" nAction:" + nAction);
				// 剩余电量百分比,单位%
				int nBatteryLeft = msg.nBatteryLeft;
				System.out.println(" nBatteryLeft:" + nBatteryLeft);
				// 事件发生时间
				NetSDKLib.NET_TIME stTime = msg.stTime;
				System.out.println(" stTime:" + stTime.toStringTime());
				int nChannelID = msg.nChannelID;// 通道号,标识子设备电池,从0开始
				System.out.println(" nChannelID:" + nChannelID);
				break;
			}
			case NET_ALARM_POWERFAULT: { // 电源故障事件(对应结构体ALARM_POWERFAULT_INFO)
				System.out.println(" 电源故障事件--------------------");
				ALARM_POWERFAULT_INFO msg = new ALARM_POWERFAULT_INFO();
				ToolKits.GetPointerData(pStuEvent, msg);
				int emPowerType = msg.emPowerType;// 电源类型，详见EM_POWER_TYPE
				System.out.println(" emPowerType:" + emPowerType);
				int emPowerFaultEvent = msg.emPowerFaultEvent; // 电源故障事件，详见EM_POWERFAULT_EVENT_TYPE
				System.out.println(" emPowerFaultEvent:" + emPowerFaultEvent);
				// 报警事件发生的时间
				NetSDKLib.NET_TIME stuTime = msg.stuTime;
				System.out.println(" stuTime:" + stuTime.toStringTime());
				// 0:开始 1:停止
				int nAction = msg.nAction;
				System.out.println(" nAction:" + nAction);
				break;
			}
			case NET_ALARM_CHASSISINTRUDED: {// 机箱入侵(防拆)报警事件(对应结构体ALARM_CHASSISINTRUDED_INFO)
				System.out.println(" 机箱入侵(防拆)报警事件--------------------");
				ALARM_CHASSISINTRUDED_INFO msg = new ALARM_CHASSISINTRUDED_INFO();
				ToolKits.GetPointerData(pStuEvent, msg);
				// 0:开始 1:停止
				int nAction = msg.nAction;
				System.out.println(" nAction:" + nAction);
				// 报警事件发生的时间
				NetSDKLib.NET_TIME stuTime = msg.stuTime;
				System.out.println(" stuTime:" + stuTime);
				int nChannelID = msg.nChannelID;// 通道号
				System.out.println(" nChannelID:" + nChannelID);
				byte[] szReaderID = msg.szReaderID;
				System.out.println(" szReaderID:" + new String(szReaderID));
				// 事件ID
				System.out.println(" nEventID:" + msg.nEventID);
				// 无线设备序列号
				System.out.println(" szSN:" + new String(msg.szSN));
				int bRealUTC = msg.bRealUTC;
				System.out.println(" bRealUTC:" + bRealUTC);
				System.out.println(" RealUTC:" + msg.RealUTC.toString());
				// 设备类型,参考EM_ALARM_CHASSISINTRUDED_DEV_TYPE
				System.out.println(" emDevType:" + msg.emDevType);
				break;
			}
			case NET_ALARM_RF_JAMMING: {// RF干扰事件(对应结构体 NET_ALARM_RF_JAMMING_INFO)
				System.out.println(" RF干扰事件-----------------------------");
				NET_ALARM_RF_JAMMING_INFO msg = new NET_ALARM_RF_JAMMING_INFO();
				ToolKits.GetPointerData(pStuEvent, msg);
				System.out.println(" nAction:" + msg.nAction);
				System.out.println(" nChannel:" + msg.nChannel);
				System.out.println(" stuUTC:" + msg.stuUTC);
				System.out.println(" szDeviceName:" + new String(msg.szDeviceName));
				break;
			}
			case NET_ALARM_ARMING_FAILURE: { // 布防失败事件(对应结构体 NET_ALARM_ARMING_FAILURE_INFO)
				System.out.println(" 布防失败事件-----------------------------");
				NET_ALARM_ARMING_FAILURE_INFO msg = new NET_ALARM_ARMING_FAILURE_INFO();
				ToolKits.GetPointerData(pStuEvent, msg);
				// 事件动作 0:脉冲
				System.out.println(" nAction:" + msg.nAction);
				// 通道号
				System.out.println(" nChannel:" + msg.nChannel);
				// 事件发生的时间,标准的（不带时区偏差的）UTC时间
				System.out.println(" stuUTC:" + msg.stuUTC.toString());
				// 布撤防模式
				System.out.println(" emMode:" + msg.emMode);
				break;
			}
			case NET_ALARM_USER_MODIFIED: { // 用户信息被修改(增加、删除、修改)事件(对应结构体 NET_ALARM_USER_MODIFIED_INFO)
				System.out.println(" 用户信息被修改(增加、删除、修改)事件-----------------------------");
				NET_ALARM_USER_MODIFIED_INFO msg = new NET_ALARM_USER_MODIFIED_INFO();
				ToolKits.GetPointerData(pStuEvent, msg);
				// 事件动作 0:脉冲
				System.out.println(" nAction:" + msg.nAction);
				// 通道号
				System.out.println(" nChannel:" + msg.nChannel);
				// 用户名称
				System.out.println(" szUser:" + new String(msg.szUser));
				// 操作类型
				System.out.println(" emOpType:" + msg.emOpType);
				// 用户类型
				System.out.println(" emUserType:" + msg.emUserType);
				break;
			}
			case NET_ALARM_AREAALARM: {// 区域报警(对应结构体ALARM_AREAALARM_INFO)
				System.out.println(" 区域报警-----------------------------");
				ALARM_AREAALARM_INFO msg = new ALARM_AREAALARM_INFO();
				ToolKits.GetPointerData(pStuEvent, msg);
				int nAreaIndex = msg.nAreaIndex;
				System.out.println(" nAreaIndex:" + nAreaIndex);
				System.out.println(" nEventID:" + msg.nEventID);
				System.out.println(" UTC:" + msg.UTC.toString());
				System.out.println(" szName:" + new String(msg.szName));
				System.out.println(" emDefenceAreaType:" + msg.emDefenceAreaType);
				System.out.println(" nIndex:" + msg.nIndex);
				System.out.println(" emTrigerType:" + msg.emTrigerType);
				break;
			}
			case NET_ALARM_ARC_OFFLINE: { // 报警接收中心离线事件(对应结构体 NET_ALARM_ARC_OFFLINE_INFO)
				System.out.println(" 报警接收中心离线事件-----------------------------");
				NET_ALARM_ARC_OFFLINE_INFO msg = new NET_ALARM_ARC_OFFLINE_INFO();
				ToolKits.GetPointerData(pStuEvent, msg);
				// 事件动作 0:脉冲
				System.out.println(" nAction:" + msg.nAction);
				// 通道号
				System.out.println(" nChannel:" + msg.nChannel);
				// 事件发生的时间,标准的（不带时区偏差的）UTC时间
				System.out.println(" stuUTC:" + msg.stuUTC.toString());
				// ARC通讯异常描述信息
				System.out.println(" szDetail:" + new String(msg.szDetail));
				break;
			}
			case NET_ALARM_MANUAL_TEST: { // 手动测试事件(对应结构体 NET_ALARM_MANUAL_TEST_INFO)
				System.out.println(" 手动测试事件-----------------------------");
				NET_ALARM_MANUAL_TEST_INFO msg = new NET_ALARM_MANUAL_TEST_INFO();
				ToolKits.GetPointerData(pStuEvent, msg);
				// 事件动作 0:脉冲
				System.out.println(" nAction:" + msg.nAction);
				// 通道号
				System.out.println(" nChannel:" + msg.nChannel);
				// 事件发生的时间,标准的（不带时区偏差的）UTC时间
				System.out.println(" stuUTC:" + msg.stuUTC.toString());
				// 配件序列号
				System.out.println(" szSN:" + new String(msg.szSN));
				// 配件名称
				System.out.println(" szName:" + new String(msg.szName));
				// 配件所属区域名称
				System.out.println(" szAreaName:" + new String(msg.szAreaName));
				break;
			}
			case NetSDKLib.NET_ALARM_WIRELESSDEV_POWERLESS: { // 探测器主电丢失事件 (对应结构体 ALARM_WIRELESSDEV_POWERLESS_INFO)
				System.out.println(" 探测器主电丢失事件-----------------------------");
				ALARM_WIRELESSDEV_POWERLESS_INFO msg = new ALARM_WIRELESSDEV_POWERLESS_INFO();
				ToolKits.GetPointerData(pStuEvent, msg);
				// 事件动作 0:脉冲
				System.out.println(" nAction:" + msg.nAction);
				// 配件序列号
				System.out.println(" szSN:" + new String(msg.szSN));
				// 配件名称
				System.out.println(" szName:" + new String(msg.szName));
				// 配件所属区域名称
				System.out.println(" szAreaName:" + new String(msg.szAreaName));
				break;
			}
			case NetSDKLib.NET_ALARM_KEYPAD_LOCK: { // 键盘锁定事件(对应结构体 ALARM_KEYPAD_LOCK_INFO)
				System.out.println(" 键盘锁定事件(-----------------------------");
				ALARM_KEYPAD_LOCK_INFO msg = new ALARM_KEYPAD_LOCK_INFO();
				ToolKits.GetPointerData(pStuEvent, msg);
				// 事件动作 0:脉冲
				System.out.println(" nAction:" + msg.nAction);
				// 通道号
				System.out.println(" nChannel:" + msg.nChannelID);
				// 事件发生的时间
				System.out.println(" stuUTC:" + msg.stuTime.toString());
				break;
			}
			case NetSDKLib.NET_ALARM_DEVICE_MODIFIED: {// 设备设息修改(增加、删除、修改)事件(对应结构体 NET_ALARM_DEVICE_MODIFIED_INFO)
				System.out.println(" 手动测试事件----------------------------");
				NET_ALARM_DEVICE_MODIFIED_INFO msg = new NET_ALARM_DEVICE_MODIFIED_INFO();
				ToolKits.GetPointerData(pStuEvent, msg);
				// 事件动作 0:脉冲
				System.out.println(" nAction:" + msg.nAction);
				// 通道号
				System.out.println(" nChannel:" + msg.nChannel);
				// 事件发生的时间,标准的（不带时区偏差的）UTC时间
				System.out.println(" stuUTC:" + msg.stuUTC.toString());
				break;
			}
			case NET_ALARM_ATS_FAULT: {// 报警传输系统故障事件(对应结构体 NET_ALARM_ATS_FAULT_INFO)
				System.out.println(" 报警传输系统故障事件--------------------------");
				NET_ALARM_ATS_FAULT_INFO msg = new NET_ALARM_ATS_FAULT_INFO();
				ToolKits.GetPointerData(pStuEvent, msg);
				// 事件动作 0:脉冲
				System.out.println(" nAction:" + msg.nAction);
				// 通道号
				System.out.println(" nChannel:" + msg.nChannel);
				// 事件发生的时间,标准的（不带时区偏差的）UTC时间
				System.out.println(" stuUTC:" + msg.stuUTC.toString());
				break;
			}
			case NET_ALARM_WIFI_FAILURE: { // wifi故障事件(对应结构体 NET_ALARM_WIFI_FAILURE_INFO)
				System.out.println(" wifi故障事件-----------------------------");
				NET_ALARM_WIFI_FAILURE_INFO msg = new NET_ALARM_WIFI_FAILURE_INFO();
				ToolKits.GetPointerData(pStuEvent, msg);
				// 事件动作 0:脉冲
				System.out.println(" nAction:" + msg.nAction);
				// 事件发生的时间,标准的（不带时区偏差的）UTC时间
				System.out.println(" stuUTC:" + msg.stuUTC.toString());
				// 配件序列号
				System.out.println(" szSN:" + new String(msg.szSN));
				// 配件名称
				System.out.println(" szName:" + new String(msg.szName));
				// wifi故障错误码 1:未知错误;2:无效的网络名称;3:无效的网络口令;4:网络故障
				System.out.println(" nErrorCode:" + msg.nErrorCode);
				// 所属区域信息个数
				System.out.println(" nAreaInfoNum:" + msg.nAreaInfoNum);
				NET_EVENT_AREAR_INFO[] stuAreaInfo = msg.stuAreaInfo;
				for (int i = 0; i < msg.nAreaInfoNum; i++) {
					NET_EVENT_AREAR_INFO info = stuAreaInfo[i];
					System.out.println(" nIndex:" + info.nIndex);
					System.out.println(" szName:" + new String(info.szName));
				}
				break;
			}
			case NET_ALARM_OVER_TEMPERATURE: { // 超温报警事件(对应结构体 NET_ALARM_OVER_TEMPERATURE_INFO)
				System.out.println(" 超温报警事件-----------------------------");
				NET_ALARM_OVER_TEMPERATURE_INFO msg = new NET_ALARM_OVER_TEMPERATURE_INFO();
				ToolKits.GetPointerData(pStuEvent, msg);
				// 事件动作 0:脉冲
				System.out.println(" nAction:" + msg.nAction);
				// 事件发生的时间,标准的（不带时区偏差的）UTC时间
				System.out.println(" stuUTC:" + msg.stuUTC.toString());
				// 配件序列号
				System.out.println(" szSN:" + new String(msg.szSN));
				// 配件名称
				System.out.println(" szName:" + new String(msg.szName));
				// 超温类型 0:温度恢复正常;1:温度超过下限;2:温度超过上限
				System.out.println(" nTemperatureType:" + msg.nTemperatureType);
				// 所属区域信息个数
				System.out.println(" nAreaInfoNum:" + msg.nAreaInfoNum);
				NET_EVENT_AREAR_INFO[] stuAreaInfo = msg.stuAreaInfo;
				for (int i = 0; i < msg.nAreaInfoNum; i++) {
					NET_EVENT_AREAR_INFO info = stuAreaInfo[i];
					System.out.println(" nIndex:" + info.nIndex);
					System.out.println(" szName:" + new String(info.szName));
				}
				break;
			}
			default:
				System.out.println("其他报警事件--------------------" + lCommand);
				break;
			}
			return true;
		}
	}

	/**
	 * 取消订阅报警信息
	 * 
	 */
	public void stopListen() {
		// 停止订阅报警
		boolean bRet = netsdk.CLIENT_StopListen(m_hLoginHandle);
		if (bRet) {
			System.out.println("取消订阅报警信息.");
		}
	}

	// 网络协议配置
	public void getSetDVRIPInfo() {
		String command = NetSDKLib.CFG_CMD_DVRIP;
		int channel = 0;
		CFG_DVRIP_INFO dvrIp = new CFG_DVRIP_INFO();

		// 获取
		if (ToolKits.GetDevConfig(m_hLoginHandle, channel, command, dvrIp)) {
			System.out.println("TCP服务端口 : " + dvrIp.nTcpPort);
			System.out.println("SSL服务端口 :" + dvrIp.nSSLPort);
			System.out.println("UDP服务端口 :" + dvrIp.nUDPPort);
			System.out.println("组播端口号 :" + dvrIp.nMCASTPort);

			// 设置，在获取的基础上设置
			if (ToolKits.SetDevConfig(m_hLoginHandle, channel, command, dvrIp)) {
				System.out.println("Set DVRIP Succeed!");
			} else {
				System.err.println("Set DVRIP Failed!" + netsdk.CLIENT_GetLastError());
			}
		} else {
			System.err.println("Get DVRIP Failed!" + netsdk.CLIENT_GetLastError());
		}
	}

	// 修改密码 ,需要先查询用户信息，再进行修改
	public void operateUserInfoTypeModifyPwd() {
		// 先查询用户信息
		// 参考UserManagementFrame类的方法CLIENT_QueryUserInfoNew

		// 新数据
		NetSDKLib.USER_INFO_NEW m_userInfoNew = new NetSDKLib.USER_INFO_NEW();
		m_userInfoNew.dwRightNum = 20; // m_userInfo.dwRightNum; //权限数
		m_userInfoNew.dwID = 1; // 用户ID
		m_userInfoNew.dwGroupID = 1 + 1; // 用户组ID

		System.arraycopy("123456".getBytes(), 0, m_userInfoNew.passWord, 0, "123456".getBytes().length);

		for (int i = 0; i < m_userInfoNew.dwRightNum; i++) {
			m_userInfoNew.rights[i] = i + 1;
		}
		m_userInfoNew.dwFouctionMask = 0x00000001;
		m_userInfoNew.byIsAnonymous = 0;

		// 原始
		NetSDKLib.USER_INFO_NEW m_userInfoNewEx = new NetSDKLib.USER_INFO_NEW();
		m_userInfoNewEx.dwRightNum = 20; // m_userInfo.dwRightNum; //权限数
		m_userInfoNewEx.dwID = 1; // 用户ID
		m_userInfoNewEx.dwGroupID = 1 + 1; // 用户组ID
		System.arraycopy("admin".getBytes(), 0, m_userInfoNewEx.name, 0, "admin".getBytes().length);
		System.arraycopy("12345678".getBytes(), 0, m_userInfoNewEx.passWord, 0, "12345678".getBytes().length);

		for (int i = 0; i < m_userInfoNewEx.dwRightNum; i++) {
			m_userInfoNewEx.rights[i] = i + 1;
		}
		m_userInfoNewEx.dwFouctionMask = 0x00000001;
		m_userInfoNewEx.byIsAnonymous = 0;
		m_userInfoNew.write();
		m_userInfoNewEx.write();

		int nOperateType = EM_OPERATE_USERINFO_TYPE.EM_OPERATE_USERINFO_TYPE_MODIFY_PWD.getValue();
		boolean if_hoperateUserInfoNew = netsdk.CLIENT_OperateUserInfoNew(m_hLoginHandle, nOperateType,
				m_userInfoNew.getPointer(), m_userInfoNewEx.getPointer(), null, 5000);
		if (if_hoperateUserInfoNew) {
			System.out.println("修改密码成功！" + new String(m_userInfoNew.passWord));
		} else {
			System.err.printf("Failed!" + String.format("0x%x", netsdk.CLIENT_GetLastError()));
		}
	}

	// 设置布防模式
	public void setAlarmRegionInfo() throws UnsupportedEncodingException {
		NET_IN_SET_ALARMMODE stuInParam = new NET_IN_SET_ALARMMODE();
		stuInParam.emArmType = EM_ARM_TYPE.EM_ARM_TYPE_DISARMING.getValue();
		String szPwd = "admin123";
		System.arraycopy(szPwd.getBytes(), 0, stuInParam.szPwd, 0, szPwd.getBytes().length);

		stuInParam.nAreaNum = 1;
		stuInParam.arrAreas[0] = 1;
		stuInParam.stuDetail.stuArmOption.emSceneMode = NET_EM_SCENE_MODE.NET_EM_SCENE_MODE_INDOOR.getValue();
		stuInParam.stuDetail.stuArmOption.emAreaarmTriggerMode = EM_AREAARM_TRIGGERMODE.EM_AREAARM_TRIGGERMODE_KEYPAD
				.getValue();
		stuInParam.stuDetail.stuArmOption.nId = 1;
		String szName = "test";
		System.arraycopy(szName.getBytes(encode), 0, stuInParam.stuDetail.stuArmOption.szName, 0,
				szName.getBytes(encode).length);
		String szClientAddress = "192.168.1.1";
		System.arraycopy(szClientAddress.getBytes(encode), 0, stuInParam.stuDetail.stuArmOption.szClientAddress, 0,
				szClientAddress.getBytes(encode).length);
		stuInParam.write();
		NET_OUT_SET_ALARMMODE stOutParam = new NET_OUT_SET_ALARMMODE();
		// 布防失败的细节扩展字段 布防个数大于8个使用此字段，pstuFailedDetailEx需要初始化,字段指针对应结构体{ @link
		// ARM_FAILED_DETAIL_EX}数组
		stOutParam.write();
		boolean bRet1 = netsdk.CLIENT_SetAlarmRegionInfo(m_hLoginHandle,
				NET_EM_SET_ALARMREGION_INFO.NET_EM_SET_ALARMREGION_INFO_ARMMODE.getValue(), stuInParam.getPointer(),
				stOutParam.getPointer(), 5000);
		if (bRet1) {						
			System.out.println("CLIENT_SetAlarmRegionInfo success\n");
			stOutParam.read();
			System.out.println(" 布防结果（ 0:成功 1:失败 ）："+stOutParam.nArmResult);						
		} else {
			System.err.printf("CLIENT_SetAlarmRegionInfo fail:" + netsdk.CLIENT_GetLastError());
		}
	}

	// 报警子系统配置
	public void setAlarmSubSystem() throws UnsupportedEncodingException {
		String command = EM_NEW_CONFIG.CFG_CMD_ALARM_SUBSYSTEM.getValue();
		int channel = 0;
		CFG_ALARM_SUBSYSTEM_INFO info = new CFG_ALARM_SUBSYSTEM_INFO();

		// 获取
		if (ToolKits.GetDevConfig(m_hLoginHandle, channel, command, info)) {
			System.out.println("名称 : " + new String(info.szName, encode).trim());

			// 设置，在获取的基础上设置
			String name = new String(info.szName, encode).trim();
			info.szName = new byte[128];// 清空数据
			System.arraycopy(name.getBytes(encode), 0, info.szName, 0, name.getBytes(encode).length);
			if (ToolKits.SetDevConfig(m_hLoginHandle, channel, command, info)) {
				System.out.println("Set alarmSubSystem Succeed!");
			} else {
				System.err.println("Set alarmSubSystem Failed!" + netsdk.CLIENT_GetLastError());
			}
		} else {
			System.err.println("Get alarmSubSystem Failed!" + netsdk.CLIENT_GetLastError());
		}
	}

	// 获取设备状态
	public void getUnifiedStatus() {
		NET_IN_UNIFIEDINFOCOLLECT_GET_DEVSTATUS inPut = new NET_IN_UNIFIEDINFOCOLLECT_GET_DEVSTATUS();
		Pointer paramInputPointer = new Memory(inPut.size());
		paramInputPointer.clear(inPut.size());
		ToolKits.SetStructDataToPointer(inPut, paramInputPointer, 0);

		NET_OUT_UNIFIEDINFOCOLLECT_GET_DEVSTATUS outPut = new NET_OUT_UNIFIEDINFOCOLLECT_GET_DEVSTATUS();
		Pointer paramOutPointer = new Memory(outPut.size());
		paramOutPointer.clear(outPut.size());
		ToolKits.SetStructDataToPointer(outPut, paramOutPointer, 0);

		boolean flg = netsdk.CLIENT_GetUnifiedStatus(m_hLoginHandle, paramInputPointer, paramOutPointer, 5000);
		if (flg) {
			ToolKits.GetPointerData(paramOutPointer, outPut);
			Native.free(Pointer.nativeValue(paramInputPointer));
			Pointer.nativeValue(paramInputPointer, 0);
			System.out.println("获取设备状态成功 ");
			int emTamperState = outPut.emTamperState;
			NET_DEVSTATUS_POWER_INFO stuPowerInfo = outPut.stuPowerInfo;
			System.out.println("emTamperState:" + emTamperState);
			System.out.println("emPowerType:" + stuPowerInfo.emPowerType);
			System.out.println("nBatteryPercent:" + stuPowerInfo.nBatteryPercent);
			System.out.println("emTamperState:" + emTamperState);
			try {
				System.out.println("szVersion:" + new String(outPut.szVersion, encode));
			} catch (UnsupportedEncodingException e) {
				e.printStackTrace();
			}
			NET_DEVSTATUS_NET_INFO stuNetInfo = outPut.stuNetInfo;
			System.out.println("nWifiIntensity:" + stuNetInfo.nWifiIntensity);
			System.out.println("nWifiSignal:" + stuNetInfo.nWifiSignal);
			System.out.println("nCellulSignal:" + stuNetInfo.nCellulSignal);
			System.out.println("nCellulIntensity:" + stuNetInfo.nCellulIntensity);
			System.out.println("emEthState:" + stuNetInfo.emEthState);
			System.out.println("n3Gflux:" + stuNetInfo.n3Gflux);
			System.out.println("n3GfluxByTime:" + stuNetInfo.n3GfluxByTime);
			System.out.println("emWifiState:" + stuNetInfo.emWifiState);
			System.out.println("emCellularstate:" + stuNetInfo.emCellularstate);
			System.out.println("nSimNum:" + stuNetInfo.nSimNum);
			NET_DEVSTATUS_SIM_INFO[] stuSimInfo = stuNetInfo.stuSimInfo;
			for (int i = 0; i < stuNetInfo.nSimNum; i++) {
				NET_DEVSTATUS_SIM_INFO sim_info = stuSimInfo[i];
				byte byIndex = sim_info.byIndex;
				int emStatus = sim_info.emStatus;
				System.out.println("byIndex:" + byIndex);
				System.out.println("emStatus:" + emStatus);
			}
		} else {
			Native.free(Pointer.nativeValue(paramInputPointer));
			Pointer.nativeValue(paramInputPointer, 0);
			System.err.println("获取设备状态失败:" + ToolKits.getErrorCode());
		}
	}

	// 先获取，再配置
	public void generalConfig() {
		// 获取
		String strCmd = NetSDKLib.CFG_CMD_DEV_GENERRAL;
		int nChn = -1;
		CFG_DEV_DISPOSITION_INFO msg = new CFG_DEV_DISPOSITION_INFO();
		if (ToolKits.GetDevConfig(m_hLoginHandle, nChn, strCmd, msg)) {
			System.out.println("序列号:" + new String(msg.szMachineName).trim());
			// 设置
			String name = "4E01D85PAKFC751";
			// 因为是先获取的，设置前需要将字段内容清空
			for (int i = 0; i < msg.szMachineName.length; i++) {
				msg.szMachineName[i] = 0;
			}
			// 数组拷贝赋值
			System.arraycopy(name.getBytes(), 0, msg.szMachineName, 0, name.getBytes().length);
			if (ToolKits.SetDevConfig(m_hLoginHandle, nChn, strCmd, msg)) {
				System.out.println("Set General Succeed!");
			} else {
				System.err.println("Set General Failed!" + ToolKits.getErrorCode());
			}
		} else {
			System.err.println("Get General Failed!" + ToolKits.getErrorCode());
		}
	}

	// 获取设备序列号
	public void getDeviceSerialNo() {
		NET_IN_GET_DEVICESERIALNO_INFO inPut = new NET_IN_GET_DEVICESERIALNO_INFO();
		inPut.write();
		NET_OUT_GET_DEVICESERIALNO_INFO outPut = new NET_OUT_GET_DEVICESERIALNO_INFO();
		outPut.write();
		boolean flg = netsdk.CLIENT_GetDeviceSerialNo(m_hLoginHandle, inPut.getPointer(), outPut.getPointer(), 5000);
		if (flg) {
			outPut.read();
			System.out.println("获取设备序列号成功 ");
			System.out.println("序列号: " + new String(outPut.szSN).trim());
		} else {
			System.err.println("获取设备序列号失败:" + ToolKits.getErrorCode());
		}
	}

	// 获取设备类型
	public void getDeviceType() {
		NET_IN_GET_DEVICETYPE_INFO inPut = new NET_IN_GET_DEVICETYPE_INFO();
		inPut.write();
		NET_OUT_GET_DEVICETYPE_INFO outPut = new NET_OUT_GET_DEVICETYPE_INFO();
		outPut.write();
		boolean flg = netsdk.CLIENT_GetDeviceType(m_hLoginHandle, inPut.getPointer(), outPut.getPointer(), 5000);
		if (flg) {
			outPut.read();
			System.out.println("获取设备类型成功 ");
			System.out.println("设备类型: " + new String(outPut.szTypeEx).trim());
		} else {
			System.err.println("获取设备类型失败:" + ToolKits.getErrorCode());
		}
	}

	// 情景模式配置
	public void cfgCmdSceneMode() {
		// 获取
		String strCmd = EM_NEW_CONFIG.CFG_CMD_SCENE_MODE.getValue();
		int nChn = -1;
		CFG_SCENE_MODE_INFO msg = new CFG_SCENE_MODE_INFO();
		if (ToolKits.GetDevConfig(m_hLoginHandle, nChn, strCmd, msg)) {
			System.out.println("当前情景模式ID号:" + msg.nCurrentID);
			// 设置，在获取的基础上设置
			if (ToolKits.SetDevConfig(m_hLoginHandle, nChn, strCmd, msg)) {
				System.out.println("Set cfgCmdSceneMode Succeed!");
			} else {
				System.err.println("Set cfgCmdSceneMode Failed!" + ToolKits.getErrorCode());
			}
		} else {
			System.err.println("Get cfgCmdSceneMode Failed!" + ToolKits.getErrorCode());
		}
	}

	// 防蜂鸣联动项使能配置信息配置
	public void cfgDisableBeepLinkage() throws UnsupportedEncodingException {
		// 先获取原先的默认配置
		NET_CFG_DISABLE_BEEP_LINKAGE_INFO info = new NET_CFG_DISABLE_BEEP_LINKAGE_INFO();
		Pointer pointer = new Memory(info.size());
		ToolKits.SetStructDataToPointer(info, pointer, 0);
		int emCfgOpType = NET_EM_CFG_OPERATE_TYPE.NET_EM_CFG_DISABLE_BEEP_LINKAGE; // 配置类型的枚举
		boolean ret1 = netsdk.CLIENT_GetConfig(m_hLoginHandle, emCfgOpType, -1, pointer, info.size(), 5000, null);
		if (!ret1) {
			System.err.println("获取防蜂鸣联动项使能配置信息失败：" + ToolKits.getErrorCode());
			return;
		} else {
			System.out.println("获取防蜂鸣联动项使能配置信息成功!");
			ToolKits.GetPointerData(pointer, info);
			System.out.println("开启撤防联动项功能总开关:" + info.bEnable);
			System.out.println("联动项配置名:" + new String(info.szName, encode));

			// 编辑配置并下发
			info.bEnable = 1;
			Pointer param = new Memory(info.size());
			ToolKits.SetStructDataToPointer(info, param, 0);
			boolean ret2 = netsdk.CLIENT_SetConfig(m_hLoginHandle, emCfgOpType, -1, param, info.size(), 5000,
					new IntByReference(0), null);
			if (!ret2) {
				System.err.println("下发防蜂鸣联动项使能配置信息配置失败：" + ToolKits.getErrorCode());
				return;
			} else {
				System.out.println("下发防蜂鸣联动项使能配置信息配置成功!");
			}
		}
	}

	// 通讯录配置
	public void cfgNETAPPCommunicationList() throws UnsupportedEncodingException {
		// 先获取原先的默认配置
		NET_NETAPP_COMMUNICATION_LIST_CFG info = new NET_NETAPP_COMMUNICATION_LIST_CFG();
		Pointer pointer = new Memory(info.size());
		ToolKits.SetStructDataToPointer(info, pointer, 0);
		int emCfgOpType = NET_EM_CFG_OPERATE_TYPE.NET_EM_CFG_DISABLE_BEEP_LINKAGE; // 配置类型的枚举
		boolean ret1 = netsdk.CLIENT_GetConfig(m_hLoginHandle, emCfgOpType, -1, pointer, info.size(), 5000, null);
		if (!ret1) {
			System.err.println("获取通讯录配置失败：" + ToolKits.getErrorCode());
			return;
		} else {
			System.out.println("获取通讯录配置成功!");
			ToolKits.GetPointerData(pointer, info);
			System.out.println("实际的通讯录配置个数:" + info.nConmmunicationListNum);

			// 编辑配置并下发
			Pointer param = new Memory(info.size());
			ToolKits.SetStructDataToPointer(info, param, 0);
			boolean ret2 = netsdk.CLIENT_SetConfig(m_hLoginHandle, emCfgOpType, -1, param, info.size(), 5000,
					new IntByReference(0), null);
			if (!ret2) {
				System.err.println("下发通讯录配置失败：" + ToolKits.getErrorCode());
				return;
			} else {
				System.out.println("下发通讯录配置成功!");
			}
		}
	}

	// RPC测试
	public void transmitCmd() {
		NET_IN_TRANSMIT_CMD inPut = new NET_IN_TRANSMIT_CMD();
		inPut.nChannel = 1;
		inPut.nHannel = 0;
		inPut.bReply = 0; // 此命令需要接收回复,0 - false 1 -true
		// 命令字节数量
		int nMessageCount = 8;
		int[] pMessageArr = new int[nMessageCount];
		pMessageArr[0] = 1;
		Pointer pMessage = new Memory(pMessageArr.length * 4);
		pMessage.clear(pMessageArr.length * 4);
		pMessage.write(0, pMessageArr, 0, pMessageArr.length);
		inPut.nMessageCount = nMessageCount;
		inPut.pMessage = pMessage;
		inPut.write();

		NET_OUT_TRANSMIT_CMD outPut = new NET_OUT_TRANSMIT_CMD();
		// 用户填写,为pMessage指针所指的数组元素数量
		int nMaxMessageCount = 8;
		int[] nMaxMessageArr = new int[nMaxMessageCount];
		Pointer pMaxMessage = new Memory(nMaxMessageArr.length * 4);
		pMaxMessage.clear(nMaxMessageArr.length * 4);
		pMaxMessage.write(0, nMaxMessageArr, 0, nMaxMessageArr.length);
		outPut.nMaxMessageCount = nMaxMessageCount;
		outPut.pMessage = pMaxMessage;
		outPut.write();
		boolean flg = netsdk.CLIENT_TransmitCmd(m_hLoginHandle, inPut.getPointer(), outPut.getPointer(), 5000);
		if (flg) {
			outPut.read();
			System.out.println("RPC测试成功 ");
		} else {
			System.err.println("RPC测试失败:" + ToolKits.getErrorCode());
		}
	}

	// 设置配件信息
	public void getAndSetAccessoryInfo() {
		NET_GET_ACCESSORY_INFO info = new NET_GET_ACCESSORY_INFO();
		info.nSNNum = 0;
		info.nMaxInfoNum = 2;
		NET_WPAN_ACCESSORY_INFO[] wpInfo = new NET_WPAN_ACCESSORY_INFO[info.nMaxInfoNum];
		for (int i = 0; i < wpInfo.length; i++) {
			wpInfo[i] = new NET_WPAN_ACCESSORY_INFO();
		}
		int len = new NET_WPAN_ACCESSORY_INFO().size() * wpInfo.length;
		Pointer wpInfoPointer = new Memory(len);
		wpInfoPointer.clear(len);
		ToolKits.SetStructArrToPointerData(wpInfo, wpInfoPointer);

		info.pstuInfo = wpInfoPointer;

		Pointer params = new Memory(info.size());
		params.clear(info.size());
		ToolKits.SetStructDataToPointer(info, params, 0);
		IntByReference intRetLen = new IntByReference(0);
		boolean bRet = netsdk.CLIENT_QueryDevState(m_hLoginHandle, NetSDKLib.NET_DEVSTATE_GET_ACCESSORY_INFO, params,
				info.size(), intRetLen, 5000);

		if (bRet) {
			ToolKits.GetPointerData(params, info);
			Native.free(Pointer.nativeValue(params));
			Pointer.nativeValue(params, 0);
			System.out.println("CLIENT_QueryDevState success!");
			int nInfoNum = info.nInfoNum;
			System.out.println("nInfoNum:" + nInfoNum);
			ToolKits.GetPointerDataToStructArr(info.pstuInfo, wpInfo);
			Native.free(Pointer.nativeValue(wpInfoPointer));
			Pointer.nativeValue(wpInfoPointer, 0);

			for (int i = 0; i < nInfoNum; i++) {
				NET_WPAN_ACCESSORY_INFO net_wpan_accessory_info = wpInfo[i];
				System.out
						.println("[" + i + "]bArmingWithoutPassword:" + net_wpan_accessory_info.bArmingWithoutPassword);
				System.out.println("[" + i + "]bRecordEnable:" + net_wpan_accessory_info.bRecordEnable);
				System.out.println("[" + i + "]bExternalAlarmEnable:" + net_wpan_accessory_info.bExternalAlarmEnable);
				try {
					System.out.println("[" + i + "]szSN:" + new String(net_wpan_accessory_info.szSN, encode));
					System.out.println("[" + i + "]szName:" + new String(net_wpan_accessory_info.szName, encode));
					System.out.println("[" + i + "]szSN:" + new String(net_wpan_accessory_info.szVersion, encode));
					System.out.println("[" + i + "]szName:" + new String(net_wpan_accessory_info.szModel, encode));
					System.out.println("[" + i + "]szSN:" + new String(net_wpan_accessory_info.szAlarmTone, encode));
				} catch (UnsupportedEncodingException e) {
					e.printStackTrace();
				}
			}
		} else {
			Native.free(Pointer.nativeValue(params));
			Pointer.nativeValue(params, 0);

			System.err.println("CLIENT_QueryDevState Failed!" + ToolKits.getErrorCode());
			return;
		}

		NET_IN_CTRL_LOWRATEWPAN_ACCESSORY_PARAM paramInput = new NET_IN_CTRL_LOWRATEWPAN_ACCESSORY_PARAM();
		paramInput.stuInfo = wpInfo[0];
		Pointer paramInputPointer = new Memory(paramInput.size());
		paramInputPointer.clear(paramInput.size());
		ToolKits.SetStructDataToPointer(paramInput, paramInputPointer, 0);
		boolean flg = netsdk.CLIENT_ControlDevice(m_hLoginHandle,
				NetSDKLib.CtrlType.CTRL_LOWRATEWPAN_SET_ACCESSORY_PARAM, paramInputPointer, 5000);
		if (flg) {
			System.out.println("设置配件信息功能成功");
		} else {
			System.err.println("设置配件信息功能失败:" + ToolKits.getErrorCode());

		}
		Native.free(Pointer.nativeValue(paramInputPointer));
		Pointer.nativeValue(paramInputPointer, 0);
	}

	// Area布撤防配置
	public void cfgAreaArmMode() throws UnsupportedEncodingException {
		// 先获取原先的默认配置
		NET_CFG_AREA_ARM_MODE_INFO info = new NET_CFG_AREA_ARM_MODE_INFO();
		Pointer pointer = new Memory(info.size());
		ToolKits.SetStructDataToPointer(info, pointer, 0);
		int emCfgOpType = NET_EM_CFG_OPERATE_TYPE.NET_EM_CFG_AREA_ARM_MODE; // 配置类型的枚举
		boolean ret1 = netsdk.CLIENT_GetConfig(m_hLoginHandle, emCfgOpType, -1, pointer, info.size(), 5000, null);
		if (!ret1) {
			System.err.println("获取Area布撤防配置信息失败：" + ToolKits.getErrorCode());
			return;
		} else {
			System.out.println("获取Area布撤防配置信息成功!");
			ToolKits.GetPointerData(pointer, info);
			System.out.println(" Area状态信息数量:" + info.nAreasNum);

			// 编辑配置并下发
			Pointer param = new Memory(info.size());
			ToolKits.SetStructDataToPointer(info, param, 0);
			boolean ret2 = netsdk.CLIENT_SetConfig(m_hLoginHandle, emCfgOpType, -1, param, info.size(), 5000,
					new IntByReference(0), null);
			if (!ret2) {
				System.err.println("下发Area布撤防配置失败：" + ToolKits.getErrorCode());
				return;
			} else {
				System.out.println("下发Area布撤防配置成功!");
			}
		}
	}

	// 机箱入侵报警(防拆报警)配置(
	public void cfgCmdChassisintrusion() {
		// 获取
		String strCmd = EM_NEW_CONFIG.CFG_CMD_CHASSISINTRUSION.getValue();
		int nChn = -1;
		CFG_CHASSISINTRUSION_INFO msg = new CFG_CHASSISINTRUSION_INFO();
		if (ToolKits.GetDevConfig(m_hLoginHandle, nChn, strCmd, msg)) {
			System.out.println("使能开关:" + msg.bEnable);
			// 设置，在获取的基础上设置
			// msg.bEnable =0;
			if (ToolKits.SetDevConfig(m_hLoginHandle, nChn, strCmd, msg)) {
				System.out.println("Set CFG_CMD_CHASSISINTRUSION Succeed!");
			} else {
				System.err.println("Set CFG_CMD_CHASSISINTRUSION Failed!" + ToolKits.getErrorCode());
			}
		} else {
			System.err.println("Get CFG_CMD_CHASSISINTRUSION Failed!" + ToolKits.getErrorCode());
		}
	}

	/**
	 * 查询设备日志，以分页方式查询
	 */
	public void queryLog() {

		// 查询条件,作为入参
		QUERY_DEVICE_LOG_PARAM param = new QUERY_DEVICE_LOG_PARAM();
		// 要查询的日志类型
		param.emLogType = EM_SDK_LOG_QUERY_TYPE.DHLOG_ALL.ordinal();

		// 通道号
		param.nChannelID = 0;
		// 开始查询的条数
		param.nStartNum = 31;
		// 结束查询的条数,30-1+1=30,查询的条数是30条
		param.nEndNum = 60;
		int logNum = param.nEndNum - param.nStartNum + 1;
		// 日志数据结构体类型,写0 c层可能校验不通过,建议写1，使用DH_DEVICE_LOG_ITEM_EX作为日志数据的结构体，
		// 因为c层对出参buffer长度的校验是以DH_DEVICE_LOG_ITEM_EX结构体长度来校验的
		// 而DH_DEVICE_LOG_ITEM_EX结构体的长度比DH_DEVICE_LOG_ITEM结构体要长得多
		param.nLogStuType = 1;

		// 要查询的起始时间段
		param.stuStartTime = new NET_TIME("2023/1/1/0/0/0");
		// 要查询的结束时间段
		param.stuEndTime = new NET_TIME("2023/2/20/12/20/23");

		// 入参
		Pointer queryParam = new Memory(param.size());
		ToolKits.SetStructDataToPointer(param, queryParam, 0);
		// 日志数据结构体
		SDK_DEVICE_LOG_ITEM_EX logBuffer = new SDK_DEVICE_LOG_ITEM_EX();
		// 出参,分配内存
		Pointer pointer = new Memory(logBuffer.size() * logNum);
		pointer.clear(logBuffer.size() * logNum);
		// 出参,查询到的日志条数
		IntByReference relogNum = new IntByReference(1);
		boolean bSet = netsdk.CLIENT_QueryDeviceLog(m_hLoginHandle, queryParam, pointer, logBuffer.size() * logNum,
				relogNum, 3000);
		System.out.println("get system log is:" + bSet);
		if (bSet) {
			System.out.println("返回的log 条数:" + relogNum.getValue());
			if (relogNum.getValue() > 0) {
				SDK_DEVICE_LOG_ITEM_EX[] arrays = (SDK_DEVICE_LOG_ITEM_EX[]) new SDK_DEVICE_LOG_ITEM_EX()
						.toArray(relogNum.getValue());
				ToolKits.GetPointerDataToStructArr(pointer, arrays);
				for (SDK_DEVICE_LOG_ITEM_EX item : arrays) {
					String time = item.getDate();
					String operator = item.getOperator(Charset.forName("GBK"));
					String operation = item.getOperation(Charset.forName("GBK"));
					String log = item.getLog(Charset.forName("GBK"));
					String detailLog = item.getDetailLog(Charset.forName("GBK"));
					System.out.println(time + "," + operator + "," + operation + "," + log + "," + detailLog);
				}
			}
		} else {
			System.out.println("get log error: the error code is " + ToolKits.getErrorCode());
		}
	}

	private LLong upgradeHandle = new LLong(0); // 升级句柄
	// 远程升级

	public void startUpgrade() {
		int emtype = EM_UPGRADE_TYPE.DH_UPGRADE_BIOS_TYPE;
		String buffer = "D:\\FeiQ\\General_ASI72XX_Chn_P_BSC_V1.000.0000000.8.R.20190423\\General_ASI72XX_Chn_P_BSC_V1.000.0000000.8.R.201904231.bin";
		System.err.printf("filePath:[%s]\n", buffer);
		upgradeHandle = netsdk.CLIENT_StartUpgradeEx(m_hLoginHandle, emtype, buffer, UpgradeCallBackEx.getInstance(),
				null);

		if (upgradeHandle.longValue() != 0) {
			boolean ret = netsdk.CLIENT_SendUpgrade(upgradeHandle);
			if (ret) {
				System.out.println("start to uppgrade...");
			} else {
				netsdk.CLIENT_StopUpgrade(upgradeHandle);
				upgradeHandle.setValue(0);
				System.err.printf("CLIENT_SendUpgrade Failed ! Last Error[%x]\n", netsdk.CLIENT_GetLastError());

				EndTest();
			}
		} else {
			System.err.printf("CLIENT_StartUpgradeEx Failed ! Last Error[%x]\n", netsdk.CLIENT_GetLastError());
			EndTest();
		}
	}

	// 升级回调，分两个阶段。第一阶段是文件发送，第二阶段是，写flash，既真正去升级。
	// 这两个阶段在回调中通过nTotalSize和nSendSize的组合方式去区分。
	private static class UpgradeCallBackEx implements NetSDKLib.fUpgradeCallBackEx {
		private static class UpgradeHolder {
			private static UpgradeCallBackEx intance = new UpgradeCallBackEx();
		}

		private UpgradeCallBackEx() {
		}

		public static UpgradeCallBackEx getInstance() {
			return UpgradeHolder.intance;
		}

		@Override
		public void invoke(LLong lLoginID, LLong lUpgradechannel, int nTotalSize, int nSendSize, Pointer dwUserData) {

			if ((-1 == nSendSize) && (0 == nTotalSize)) // 成功
			{
				System.out.printf("Upgrade Success!! \r\n");
			} else if ((-2 == nSendSize) && (0 == nTotalSize)) // 升级失败
			{
				System.out.printf("Upgrade Failed!! \r\n");
			} else {
				if (nTotalSize != -1) // 文件传输 进度
				{
					// 计算进度
					NumberFormat ss = NumberFormat.getInstance();
					ss.setMaximumFractionDigits(2);
					String result = ss.format((float) nSendSize / (float) nTotalSize * 100);

					System.out.println("Upgrade file transmite pos:" + result + "%");
				} else // 升级进度
				{
					// 进度
					System.out.printf("System Upgrade pos:%d !! \r\n", nSendSize);
				}
			}
		}
	}

	// 停止远程升级
	public void stopUpgrade() {
		if (upgradeHandle.longValue() != 0) {
			netsdk.CLIENT_StopUpgrade(upgradeHandle);
			upgradeHandle.setValue(0);
			System.out.printf("CLIENT_StopUpgrade upgradeHandle:%d:...", upgradeHandle);
		}
	}

	// 手动测试
	public void manualTest() {
		NET_IN_MANUAL_TEST inPut = new NET_IN_MANUAL_TEST();
		// 测试ID，每次下发的测试ID不一样
		inPut.dwTestID = 1;
		// 测试的通道号，可以对应某一个要测试的SIA服务器
		inPut.nChannel = 1;
		inPut.write();
		NET_OUT_MANUAL_TEST outPut = new NET_OUT_MANUAL_TEST();
		outPut.write();
		boolean flg = netsdk.CLIENT_ManualTest(m_hLoginHandle, inPut.getPointer(), outPut.getPointer(), 5000);
		if (flg) {
			System.out.println("手动测试成功 ");
			outPut.read();
			// 结果 1：测试成功，结果同步返回 2：发送测试请求成功，结果异步返回 3：测试失败
			System.out.println(" nTestResult: " + outPut.nTestResult);
		} else {
			System.err.println("手动测试失败:" + ToolKits.getErrorCode());
		}
	}

	// 添加报警用户
	public void addAlarmUser() throws UnsupportedEncodingException {
		NET_IN_ADD_ALARM_USER stuIn = new NET_IN_ADD_ALARM_USER();
		System.arraycopy("2".getBytes(), 0, stuIn.stuAlarmUser.szID, 0, "2".getBytes().length);
		stuIn.stuAlarmUser.emUserStatus = EM_GETUSERINFOBYCONDITION_USER_STATUS.EM_GETUSERINFOBYCONDITION_USER_STATUS_ACTIVATED
				.getValue();
		System.arraycopy("zhangsan3".getBytes(encode), 0, stuIn.stuAlarmUser.szName, 0,
				"zhangsan3".getBytes(encode).length);
		System.arraycopy("2581".getBytes(), 0, stuIn.stuAlarmUser.szPassword, 0, "2581".getBytes().length);

		stuIn.stuAlarmUser.nAuthorityListNum = 1;
		stuIn.stuAlarmUser.emAuthorityList[0] = EM_ALARM_USERAUTHORITY.EM_ALARM_USERAUTHORITY_DISARM.getValue();
		stuIn.stuAlarmUser.emGroup = EM_ALARM_USER_GROUP.EM_ALARM_USER_GROUP_OPERATOR.getValue();
		stuIn.stuAlarmUser.emUserType = EM_GETUSERINFOBYCONDITION_USER_TYPE.EM_GETUSERINFOBYCONDITION_USER_TYPE_KEYPAD
				.getValue();
		stuIn.stuAlarmUser.nInterval = 10;
		stuIn.stuAlarmUser.stuAccessAllowTimeStart.dwYear = 2023;
		stuIn.stuAlarmUser.stuAccessAllowTimeStart.dwMonth = 1;
		stuIn.stuAlarmUser.stuAccessAllowTimeStart.dwDay = 1;
		stuIn.stuAlarmUser.stuAccessAllowTimeStart.dwHour = 0;
		stuIn.stuAlarmUser.stuAccessAllowTimeStart.dwMinute = 0;
		stuIn.stuAlarmUser.stuAccessAllowTimeStart.dwSecond = 0;
		stuIn.stuAlarmUser.stuAccessAllowTimeEnd.dwYear = 2023;
		stuIn.stuAlarmUser.stuAccessAllowTimeEnd.dwMonth = 12;
		stuIn.stuAlarmUser.stuAccessAllowTimeEnd.dwDay = 30;
		stuIn.stuAlarmUser.stuAccessAllowTimeEnd.dwHour = 23;
		stuIn.stuAlarmUser.stuAccessAllowTimeEnd.dwMinute = 59;
		stuIn.stuAlarmUser.stuAccessAllowTimeEnd.dwSecond = 59;
		System.arraycopy("Memo information".getBytes(encode), 0, stuIn.stuAlarmUser.szMemo, 0,
				"Memo information".getBytes(encode).length);
		stuIn.stuAlarmUser.nSubSystemNum = 2;
		stuIn.stuAlarmUser.nSubSystems[0] = 1;
		stuIn.stuAlarmUser.nSubSystems[1] = 2;
		stuIn.stuAlarmUser.nZoneNum = 2;
		stuIn.stuAlarmUser.nZones[0] = 1;
		stuIn.stuAlarmUser.nZones[1] = 2;
		stuIn.stuAlarmUser.stuOneClickArming.bEnable = 1;
		stuIn.stuAlarmUser.stuOneClickArming.emArmMode = EM_ARM_TYPE.EM_ARM_TYPE_TOTAL_ARMING.getValue();
		stuIn.stuAlarmUser.stuOneClickArming.emFunction = EM_ALARM_ONECLICKARMING_FUNCTION.EM_ALARM_ONECLICKARMING_FUNCTION_ONOFF
				.getValue();
		stuIn.stuAlarmUser.stuOneClickArming.emTriggerOption = EM_ALARM_ONECLICKARMING_TRIGGEROPTION.EM_ALARM_ONECLICKARMING_TRIGGEROPTION_IMPULSE
				.getValue();
		stuIn.stuAlarmUser.stuOneClickArming.emArmProfile = NET_EM_SCENE_MODE.NET_EM_SCENE_MODE_OUTDOOR.getValue();
		NET_ALARM_USER_EXTERN pUserExtern = new NET_ALARM_USER_EXTERN();
		pUserExtern.nCardNum = 0;
		System.arraycopy("ASDF".getBytes(), 0, pUserExtern.szCard[0].data, 0, "ASDF".getBytes().length);
		System.arraycopy("QWER".getBytes(), 0, pUserExtern.szCard[1].data, 0, "QWER".getBytes().length);
		System.arraycopy("2581".getBytes(), 0, pUserExtern.szDuressPassword, 0, "2581".getBytes().length);
		stuIn.stuAlarmUser.pstuAlarmUserExtern = new Memory(pUserExtern.size());
		stuIn.stuAlarmUser.pstuAlarmUserExtern.clear(pUserExtern.size());
		ToolKits.SetStructDataToPointer(pUserExtern, stuIn.stuAlarmUser.pstuAlarmUserExtern, 0);
		stuIn.write();
		NET_OUT_ADD_ALARM_USER stuOut = new NET_OUT_ADD_ALARM_USER();
		stuOut.write();
		boolean flg = netsdk.CLIENT_AddAlarmUser(m_hLoginHandle, stuIn.getPointer(), stuOut.getPointer(), 5000);
		if (flg) {
			System.out.println("添加报警用户成功 ");
			stuOut.read();
		} else {
			System.err.println("添加报警用户失败:" + ToolKits.getErrorCode());
		}
		// 注意：szID、szName、szPassword和szDuressPassword参数不能和已有的重复；暂不支持使用“布防”枚举
	}

	// 修改报警用户
	public void modifyAlarmUser() throws UnsupportedEncodingException {
		NET_IN_MODIFY_ALARM_USER stuIn = new NET_IN_MODIFY_ALARM_USER();
		System.arraycopy("43197217421".getBytes(), 0, stuIn.szUserID, 0, "43197217421".getBytes().length);// 这里的ID目前没有支持的协议可以获取，使用的时候先通过其他方式获取再来这填写
		System.arraycopy("2".getBytes(), 0, stuIn.stuAlarmUser.szID, 0, "2".getBytes().length);
		stuIn.stuAlarmUser.emUserStatus = EM_GETUSERINFOBYCONDITION_USER_STATUS.EM_GETUSERINFOBYCONDITION_USER_STATUS_ACTIVATED
				.getValue();
		System.arraycopy("zhangsan4".getBytes(encode), 0, stuIn.stuAlarmUser.szName, 0,
				"zhangsan4".getBytes(encode).length);
		System.arraycopy("2582".getBytes(), 0, stuIn.stuAlarmUser.szPassword, 0, "2582".getBytes().length);

		stuIn.stuAlarmUser.nAuthorityListNum = 1;
		stuIn.stuAlarmUser.emAuthorityList[0] = EM_ALARM_USERAUTHORITY.EM_ALARM_USERAUTHORITY_DISARM.getValue();
		stuIn.stuAlarmUser.emGroup = EM_ALARM_USER_GROUP.EM_ALARM_USER_GROUP_OPERATOR.getValue();
		stuIn.stuAlarmUser.emUserType = EM_GETUSERINFOBYCONDITION_USER_TYPE.EM_GETUSERINFOBYCONDITION_USER_TYPE_KEYPAD
				.getValue();
		stuIn.stuAlarmUser.nInterval = 10;
		stuIn.stuAlarmUser.stuAccessAllowTimeStart.dwYear = 2023;
		stuIn.stuAlarmUser.stuAccessAllowTimeStart.dwMonth = 1;
		stuIn.stuAlarmUser.stuAccessAllowTimeStart.dwDay = 1;
		stuIn.stuAlarmUser.stuAccessAllowTimeStart.dwHour = 0;
		stuIn.stuAlarmUser.stuAccessAllowTimeStart.dwMinute = 0;
		stuIn.stuAlarmUser.stuAccessAllowTimeStart.dwSecond = 0;
		stuIn.stuAlarmUser.stuAccessAllowTimeEnd.dwYear = 2023;
		stuIn.stuAlarmUser.stuAccessAllowTimeEnd.dwMonth = 12;
		stuIn.stuAlarmUser.stuAccessAllowTimeEnd.dwDay = 30;
		stuIn.stuAlarmUser.stuAccessAllowTimeEnd.dwHour = 23;
		stuIn.stuAlarmUser.stuAccessAllowTimeEnd.dwMinute = 59;
		stuIn.stuAlarmUser.stuAccessAllowTimeEnd.dwSecond = 59;
		System.arraycopy("Memo information".getBytes(encode), 0, stuIn.stuAlarmUser.szMemo, 0,
				"Memo information".getBytes(encode).length);
		stuIn.stuAlarmUser.nSubSystemNum = 2;
		stuIn.stuAlarmUser.nSubSystems[0] = 1;
		stuIn.stuAlarmUser.nSubSystems[1] = 2;
		stuIn.stuAlarmUser.nZoneNum = 2;
		stuIn.stuAlarmUser.nZones[0] = 1;
		stuIn.stuAlarmUser.nZones[1] = 2;
		stuIn.stuAlarmUser.stuOneClickArming.bEnable = 1;
		stuIn.stuAlarmUser.stuOneClickArming.emArmMode = EM_ARM_TYPE.EM_ARM_TYPE_TOTAL_ARMING.getValue();
		stuIn.stuAlarmUser.stuOneClickArming.emFunction = EM_ALARM_ONECLICKARMING_FUNCTION.EM_ALARM_ONECLICKARMING_FUNCTION_ONOFF
				.getValue();
		stuIn.stuAlarmUser.stuOneClickArming.emTriggerOption = EM_ALARM_ONECLICKARMING_TRIGGEROPTION.EM_ALARM_ONECLICKARMING_TRIGGEROPTION_IMPULSE
				.getValue();
		stuIn.stuAlarmUser.stuOneClickArming.emArmProfile = NET_EM_SCENE_MODE.NET_EM_SCENE_MODE_OUTDOOR.getValue();
		NET_ALARM_USER_EXTERN pUserExtern = new NET_ALARM_USER_EXTERN();
		pUserExtern.nCardNum = 2;
		System.arraycopy("ASDF1".getBytes(), 0, pUserExtern.szCard[0].data, 0, "ASDF1".getBytes().length);
		System.arraycopy("QWER1".getBytes(), 0, pUserExtern.szCard[1].data, 0, "QWER1".getBytes().length);
		System.arraycopy("2582".getBytes(), 0, pUserExtern.szDuressPassword, 0, "2582".getBytes().length);
		stuIn.stuAlarmUser.pstuAlarmUserExtern = new Memory(pUserExtern.size());
		stuIn.stuAlarmUser.pstuAlarmUserExtern.clear(pUserExtern.size());
		ToolKits.SetStructDataToPointer(pUserExtern, stuIn.stuAlarmUser.pstuAlarmUserExtern, 0);
		stuIn.write();

		NET_OUT_MODIFY_ALARM_USER stuout = new NET_OUT_MODIFY_ALARM_USER();
		stuout.write();
		boolean flg = netsdk.CLIENT_ModifyAlarmUser(m_hLoginHandle, stuIn.getPointer(), stuout.getPointer(), 5000);
		if (flg) {
			System.out.println("修改报警用户成功 ");
			stuout.read();
		} else {
			System.err.println("修改报警用户失败:" + ToolKits.getErrorCode());
		}
		// 注意：szID、szName、szPassword和szDuressPassword参数不能和已有的重复；暂不支持使用“布防”枚举
	}

	// 修改报警用户密码
	public void modifyAlarmUserPassword() {
		NET_IN_MODIFY_ALARM_USER_PASSWORD inPut = new NET_IN_MODIFY_ALARM_USER_PASSWORD();
		String szUserID = "43196973290"; // 这里的ID目前没有支持的协议可以获取，使用的时候先通过其他方式获取再来这填写
		System.arraycopy(szUserID.getBytes(), 0, inPut.szUserID, 0, szUserID.getBytes().length);
		System.arraycopy("2590".getBytes(), 0, inPut.szOldPassword, 0, "2590".getBytes().length);
		System.arraycopy("2591".getBytes(), 0, inPut.szNewPassword, 0, "2591".getBytes().length);
		inPut.write();
		NET_OUT_MODIFY_ALARM_USER_PASSWORD outPut = new NET_OUT_MODIFY_ALARM_USER_PASSWORD();
		outPut.write();
		boolean flg = netsdk.CLIENT_ModifyAlarmUserPassword(m_hLoginHandle, inPut.getPointer(), outPut.getPointer(),
				5000);
		if (flg) {
			System.out.println("修改报警用户密码成功 ");
			outPut.read();
		} else {
			System.err.println("修改报警用户密码失败:" + ToolKits.getErrorCode());
		}
	}

	// 删除报警用户
	public void deleteAlarmUser() {
		NET_IN_DELETE_ALARM_USER inPut = new NET_IN_DELETE_ALARM_USER();
		String szUserID = "43197217421"; // 这里的ID目前没有支持的协议可以获取，使用的时候先通过其他方式获取再来这填写
		System.arraycopy(szUserID.getBytes(), 0, inPut.szUserID, 0, szUserID.getBytes().length);
		inPut.write();
		NET_OUT_DELETE_ALARM_USER outPut = new NET_OUT_DELETE_ALARM_USER();
		outPut.write();
		boolean flg = netsdk.CLIENT_DeleteAlarmUser(m_hLoginHandle, inPut.getPointer(), outPut.getPointer(), 5000);
		if (flg) {
			System.out.println("删除报警用户成功 ");
			outPut.read();
		} else {
			System.err.println("删除报警用户失败:" + ToolKits.getErrorCode());
		}
	}

	// 网络配置
	public void getSetNetWorkInfo() {
		String command = NetSDKLib.CFG_CMD_NETWORK;
		int channel = 0;
		CFG_NETWORK_INFO network = new CFG_NETWORK_INFO();

		// 获取
		if (ToolKits.GetDevConfig(m_hLoginHandle, channel, command, network)) {
			System.out.println("主机名称 : " + new String(network.szHostName).trim());
			for (int i = 0; i < network.nInterfaceNum; i++) {
				System.out.println("网络接口名称 : " + new String(network.stuInterfaces[i].szName).trim());
				System.out.println("ip地址 : " + new String(network.stuInterfaces[i].szIP).trim());
				System.out.println("子网掩码 : " + new String(network.stuInterfaces[i].szSubnetMask).trim());
				System.out.println("默认网关 : " + new String(network.stuInterfaces[i].szDefGateway).trim());
				System.out.println(
						"DNS服务器地址 : " + new String(network.stuInterfaces[i].szDnsServersArr[0].szDnsServers).trim()
								+ "\n" + new String(network.stuInterfaces[i].szDnsServersArr[1].szDnsServers).trim());
				System.out.println("MAC地址 : " + new String(network.stuInterfaces[i].szMacAddress).trim());
			}

			// 设置，在获取的基础上设置
			// String szIp = "172.23.1.101";
			// System.arraycopy(szIp.getBytes(), 0, network.stuInterfaces[0].szIP, 0,
			// szIp.getBytes().length); // 要用数组拷贝
			if (ToolKits.SetDevConfig(m_hLoginHandle, channel, command, network)) {
				System.out.println("Set NETWORK Succeed!");
			} else {
				System.err.println("Set NETWORK Failed!" + netsdk.CLIENT_GetLastError());
			}

		} else {
			System.err.println("Get NETWORK Failed!" + netsdk.CLIENT_GetLastError());
		}
	}

	// WLAN配置
	public void cfgCmdWlan() {
		String command = EM_NEW_CONFIG.CFG_CMD_WLAN.getValue();
		int channel = -1;
		CFG_NETAPP_WLAN network = new CFG_NETAPP_WLAN();

		// 获取
		if (ToolKits.GetDevConfig(m_hLoginHandle, channel, command, network)) {
			System.out.println("stuWlanInfo有效的WLAN配置个数 : " + network.nNum);

			// 设置，在获取的基础上设置
			if (ToolKits.SetDevConfig(m_hLoginHandle, channel, command, network)) {
				System.out.println("Set CFG_CMD_WLAN Succeed!");
			} else {
				System.err.println("Set CFG_CMD_WLAN Failed!" + netsdk.CLIENT_GetLastError());
			}
		} else {
			System.err.println("Get CFG_CMD_WLAN Failed!" + netsdk.CLIENT_GetLastError());
		}
	}

	// 查询无线网络接入点信息
	public void queryWlanAccessPoint() {
		// 入参
		NET_IN_WLAN_ACCESSPOINT pInBuf = new NET_IN_WLAN_ACCESSPOINT();
		pInBuf.write();
		// 出参
		NET_OUT_WLAN_ACCESSPOINT pOutBuf = new NET_OUT_WLAN_ACCESSPOINT();
		pOutBuf.write();
		boolean flg = netsdk.CLIENT_QueryDevInfo(m_hLoginHandle, NetSDKLib.NET_QUERY_WLAN_ACCESSPOINT,
				pInBuf.getPointer(), pOutBuf.getPointer(), null, 3000);
		if (flg) {
			pOutBuf.read();
			System.out.println(" 无线网络接入点个数: " + pOutBuf.nCount);
			NET_WLAN_ACCESSPOINT_INFO[] stuInfo = pOutBuf.stuInfo;
			for (int i = 0; i < pOutBuf.nCount; i++) {
				System.out.println("第" + (i + 1) + "个接入点信息--------");
				try {
					System.out.println(" 无线网络名称: " + new String(stuInfo[i].szSSID, encode));
				} catch (UnsupportedEncodingException e) {
					e.printStackTrace();
				}
				System.out.println(" 信号强度 范围0-100: " + stuInfo[i].nStrength);
				System.out.println(" 认证模式: " + stuInfo[i].nAuthMode);
				System.out.println(" nEncrAlgr: " + stuInfo[i].nEncrAlgr);
			}
		} else {
			System.err.println("查询无线网络接入点信息:" + ENUMERROR.getErrorMessage());
		}
	}

	// 无线网络连接设置
	public void cfgCmdWireless() {
		String command = EM_NEW_CONFIG.CFG_CMD_WIRELESS.getValue();
		int channel = -1;
		CFG_WIRELESS_INFO network = new CFG_WIRELESS_INFO();
		// 获取
		if (ToolKits.GetDevConfig(m_hLoginHandle, channel, command, network)) {
			System.out.println("接入的2G网络名称 : " + EM_CFG_APN.getNoteByValue(network.emAPN));

			// 设置，在获取的基础上设置
			if (ToolKits.SetDevConfig(m_hLoginHandle, channel, command, network)) {
				System.out.println("Set CFG_CMD_WIRELESS Succeed!");
			} else {
				System.err.println("Set CFG_CMD_WIRELESS Failed!" + netsdk.CLIENT_GetLastError());
			}

		} else {
			System.err.println("Get CFG_CMD_WIRELESS Failed!" + netsdk.CLIENT_GetLastError());
		}
	}

	/**
	 * 增加无线设备信息
	 * 
	 * @throws UnsupportedEncodingException
	 */
	public void lowrateWpanAdd() throws UnsupportedEncodingException {
		NET_CTRL_LOWRATEWPAN_ADD info = new NET_CTRL_LOWRATEWPAN_ADD();
		info.stuCodeIDInfo.nWirelessId = 123456789;
		info.stuCodeIDInfo.emType = NET_WIRELESS_DEVICE_TYPE.NET_WIRELESS_DEVICE_TYPE_KEYBOARD.getValue();
		String szName = "admin";
		System.arraycopy(szName.getBytes(encode), 0, info.stuCodeIDInfo.szName, 0, szName.getBytes(encode).length);
		info.stuCodeIDInfo.bEnable = 0;
		String szCustomName = "wifi-7";
		System.arraycopy(szCustomName.getBytes(encode), 0, info.stuCodeIDInfo.szCustomName, 0,
				szCustomName.getBytes(encode).length);
		info.stuCodeIDInfo.emMode = EM_WIRELESS_DEVICE_MODE.EM_WIRELESS_DEVICE_MODE_NORMAL.getValue();
		info.stuCodeIDInfo.emSenseMethod = EM_CODEID_SENSE_METHOD_TYPE.EM_CODEID_SENSE_METHOD_TYPE_MOBILE_SENSOR
				.getValue();
		String szSerialNumber = "No.xxxxx123";
		System.arraycopy(szSerialNumber.getBytes(encode), 0, info.stuCodeIDInfo.szSerialNumber, 0,
				szSerialNumber.getBytes(encode).length);
		info.stuCodeIDInfo.nTaskID = 5;
		info.write();
		if (!netsdk.CLIENT_ControlDeviceEx(m_hLoginHandle, NetSDKLib.CtrlType.CTRLTYPE_CTRL_LOWRATEWPAN_ADD,
				info.getPointer(), null, 3000)) {
			info.read();
			System.err.println("lowrateWpanAdd Failed." + netsdk.CLIENT_GetLastError());
		} else {
			System.out.println("lowrateWpanAdd Success.");
		}
	}

	/**
	 * 修改配件参数
	 */
	public void lowrateSetAccessoryParam() {
		NET_IN_CTRL_LOWRATEWPAN_ACCESSORY_PARAM info = new NET_IN_CTRL_LOWRATEWPAN_ACCESSORY_PARAM();
		// 可以参考getAndSetAccessoryInfo的配置写法
		info.write();
		if (!netsdk.CLIENT_ControlDeviceEx(m_hLoginHandle, NetSDKLib.CtrlType.CTRL_LOWRATEWPAN_SET_ACCESSORY_PARAM,
				info.getPointer(), null, 3000)) {
			info.read();
			System.err.println("lowrateSetAccessoryParam Failed." + netsdk.CLIENT_GetLastError());
		} else {
			System.out.println("lowrateSetAccessoryParam Success.");
		}
	}

	/**
	 * 删除指定无线设备
	 */
	public void lowrateWpanRemove() {
		NET_CTRL_LOWRATEWPAN_REMOVE info = new NET_CTRL_LOWRATEWPAN_REMOVE();
		info.nWirelessId = 123456789;
		info.write();
		if (!netsdk.CLIENT_ControlDeviceEx(m_hLoginHandle, NetSDKLib.CtrlType.CTRLTYPE_CTRL_LOWRATEWPAN_REMOVE,
				info.getPointer(), null, 3000)) {
			info.read();
			System.err.println("lowrateWpanRemove Failed." + netsdk.CLIENT_GetLastError());
		} else {
			System.out.println("lowrateWpanRemove Success.");
		}
	}

	/**
	 * 删除所有的无线设备信息
	 */
	public void lowrateWpanRemoveAll() {
		NET_CTRL_LOWRATEWPAN_REMOVEALL info = new NET_CTRL_LOWRATEWPAN_REMOVEALL();
		info.write();
		if (!netsdk.CLIENT_ControlDeviceEx(m_hLoginHandle, NetSDKLib.CtrlType.CTRLTYPE_CTRL_LOWRATEWPAN_REMOVEALL,
				info.getPointer(), null, 3000)) {
			info.read();
			System.err.println("lowrateWpanRemoveAll Failed." + netsdk.CLIENT_GetLastError());
		} else {
			System.out.println("lowrateWpanRemoveAll Success.");
		}
	}

	// 订阅无线对码信息句柄
	private NetSDKLib.LLong attachHandle = new NetSDKLib.LLong(0);

	/**
	 * 订阅无线对码信息接口
	 */
	public void attachLowRateWPAN() {
		NET_IN_ATTACH_LOWRATEWPAN input = new NET_IN_ATTACH_LOWRATEWPAN();
		input.cbAttachLowRateWPANCB = AttachLowRateWPANCB.getInstance();
		input.write();
		NET_OUT_ATTACH_LOWRATEWPAN outPut = new NET_OUT_ATTACH_LOWRATEWPAN();
		outPut.write();
		attachHandle = netsdk.CLIENT_AttachLowRateWPAN(m_hLoginHandle, input.getPointer(), outPut.getPointer(), 3000);
		if (attachHandle.longValue() == 0) {
			System.err.printf("CLIENT_AttachLowRateWPAN Failed" + ToolKits.getErrorCode());
		} else {
			System.out.printf("CLIENT_AttachLowRateWPAN Success\n");
		}

	}

	/**
	 * 取消订阅无线对码信息接口
	 */
	public void detachLowRateWPAN() {
		boolean isSuccess = netsdk.CLIENT_DetachLowRateWPAN(attachHandle);
		if (isSuccess) {
			System.out.println(" CLIENT_AttachVideoStatistics Success");
		} else {
			System.err.printf(" CLIENT_AttachVideoStatistics Failed：" + ToolKits.getErrorCode());
		}
	}

	/**
	 * 对码信息回调函数原形，
	 */
	private static class AttachLowRateWPANCB implements NetSDKLib.fAttachLowRateWPANCB {
		private static AttachLowRateWPANCB instance;

		public static AttachLowRateWPANCB getInstance() {
			if (instance == null) {
				instance = new AttachLowRateWPANCB();
			}
			return instance;
		}

		@Override
		public void invoke(LLong lLoginID, LLong lAttachHandle, Pointer stuBuf, int emError, Pointer dwUser) {
			// 请不要在回调函数进行耗时操作
			System.out.println(" 对码错误类型: " + NET_CODEID_ERROR_TYPE.getNoteByValue(emError));
			NetSDKLib.NET_CODEID_INFO msg = new NetSDKLib.NET_CODEID_INFO();
			ToolKits.GetPointerData(stuBuf, msg);
			System.out.println(" 无线ID号：" + msg.nWirelessId);
			System.out.println(" 无线设备类型：" + msg.emType);
			System.out.println(" 无线设备序列号：" + new String(msg.szSerialNumber));
			System.out.println(" 用户名: " + new String(msg.szName));
		}
	}

	/******************************** 测试控制台 ***************************************/

	// 配置登陆地址，端口，用户名，密码
	private String m_strIpAddr = "172.24.104.188";
	private int m_nPort = 37777;
	private String m_strUser = "admin";
	private String m_strPassword = "Admin123";

	public static void main(String[] args) {
		GatewayDemo demo = new GatewayDemo();
		demo.InitTest();
		demo.RunTest();
		demo.EndTest();

	}

	/**
	 * 初始化测试
	 */
	public void InitTest() {
		GatewayDemo.Init();
		this.loginWithHighLevel();
	}

	/**
	 * 加载测试内容
	 */
	public void RunTest() {
		CaseMenu menu = new CaseMenu();
		// 6.1.1 通用功能
		menu.addItem(new CaseMenu.Item(this, "网络协议配置配置", "getSetDVRIPInfo"));
		menu.addItem(new CaseMenu.Item(this, "设备密码更改", "operateUserInfoTypeModifyPwd"));

		// 6.1.2 ROOM与布撤防相关
		menu.addItem(new CaseMenu.Item(this, "设置布防模式", "setAlarmRegionInfo"));
		menu.addItem(new CaseMenu.Item(this, "报警子系统配置", "setAlarmSubSystem"));

		// 6.1.3网关/设备信息
		menu.addItem(new CaseMenu.Item(this, "获取设备状态", "getUnifiedStatus"));
		menu.addItem(new CaseMenu.Item(this, "普通配置", "generalConfig"));
		menu.addItem(new CaseMenu.Item(this, "获取设备序列号", "getDeviceSerialNo"));
		menu.addItem(new CaseMenu.Item(this, "获取设备类型", "getDeviceType"));

		// 6.1.4网关/设备管理
		menu.addItem(new CaseMenu.Item(this, "情景模式配置 ", "cfgCmdSceneMode"));
		menu.addItem(new CaseMenu.Item(this, "防蜂鸣联动项使能配置信息配置 ", "cfgDisableBeepLinkage"));
		menu.addItem(new CaseMenu.Item(this, "通讯录配置", "cfgNETAPPCommunicationList"));
		menu.addItem(new CaseMenu.Item(this, "RPC测试", "transmitCmd"));
		menu.addItem(new CaseMenu.Item(this, "设置配件信息", "getAndSetAccessoryInfo"));
		menu.addItem(new CaseMenu.Item(this, "Area布撤防配置 ", "cfgAreaArmMode"));
		menu.addItem(new CaseMenu.Item(this, "机箱入侵报警(防拆报警)配置 ", "cfgCmdChassisintrusion"));
		menu.addItem(new CaseMenu.Item(this, "查询设备日志 ", "queryLog"));
		menu.addItem(new CaseMenu.Item(this, "远程升级", "startUpgrade"));
		menu.addItem(new CaseMenu.Item(this, "停止远程升级", "stopUpgrade"));

		// 6.1.5接警中心（SIA功能）
		menu.addItem(new CaseMenu.Item(this, "手动测试", "manualTest"));

		// 6.1.6键盘用户、卡片管理
		menu.addItem(new CaseMenu.Item(this, "添加报警用户", "addAlarmUser"));
		menu.addItem(new CaseMenu.Item(this, "修改报警用户", "modifyAlarmUser"));
		menu.addItem(new CaseMenu.Item(this, "修改报警用户密码", "modifyAlarmUserPassword"));
		menu.addItem(new CaseMenu.Item(this, "删除报警用户", "deleteAlarmUser"));

		// 6.1.7 网络设置
		menu.addItem(new CaseMenu.Item(this, "有线网络配置", "getSetNetWorkInfo"));
		menu.addItem(new CaseMenu.Item(this, "WLAN配置", "cfgCmdWlan"));
		menu.addItem(new CaseMenu.Item(this, "查询无线网络接入点信息", "queryWlanAccessPoint"));
		menu.addItem(new CaseMenu.Item(this, "无线网络连接设置", "cfgCmdWireless"));

		// 6.1.8 配件管理与信息展示
		menu.addItem(new CaseMenu.Item(this, "配件添加", "lowrateWpanAdd"));
		menu.addItem(new CaseMenu.Item(this, "修改配件参数", "lowrateSetAccessoryParam"));
		menu.addItem(new CaseMenu.Item(this, "删除指定无线设备", "lowrateWpanRemove"));
		menu.addItem(new CaseMenu.Item(this, "删除所有的无线设备信息", "lowrateWpanRemoveAll"));

		menu.addItem(new CaseMenu.Item(this, "配件信息展示、修改配件参数", "getAndSetAccessoryInfo"));

		menu.addItem(new CaseMenu.Item(this, "订阅无线对码信息接口", "attachLowRateWPAN"));
		menu.addItem(new CaseMenu.Item(this, "取消订阅无线对码信息接口", "detachLowRateWPAN"));

		// 6.1.9 消息推送
		menu.addItem(new CaseMenu.Item(this, "订阅报警信息", "startListen"));
		menu.addItem(new CaseMenu.Item(this, "取消订阅报警信息", "stopListen"));
		menu.run();
	}

	/**
	 * 结束测试
	 */
	public void EndTest() {
		System.out.println("End Test");
		this.logOut(); // 登出设备
		System.out.println("See You...");
		GatewayDemo.cleanAndExit(); // 清理资源并退出
	}
	/******************************** 结束 ***************************************/
}
